package com.baitengsoft.patentapimonitor.common.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * @author wangze
 * @date 2018-02-12 9:47.
 **/
@Component
@PropertySource(value = "classpath:/ScheduleJob.Properties", encoding = "UTF-8")
public class SysParamaterUtil {
    @Autowired
    Environment env;


    /**
     * 获取参数值
     *
     * @param propertyName
     * @return
     */
    public String getPropertyValue(String propertyName) {
        if (!env.containsProperty(propertyName)) {
            throw new RuntimeException("当前property文件不存在key");
        }
        return env.getProperty(propertyName);
    }

    public String getBeanName() {
        return this.getPropertyValue("beanName");
    }

    public String getMethodName() {
        return this.getPropertyValue("methodName");
    }

    /**
     * 获取api地址
     *
     * @return
     */
    public String getApiUrl() {
        return this.getPropertyValue("scheduleJobUrlAndPort");
    }

    /**
     * 初始化接口
     *
     * @return
     */
    public String getInitOssDataUrl() {
        return this.getApiUrl() + this.getPropertyValue("initOssDataUrl");
    }

    /**
     * 保存quartz接口
     *
     * @return
     */
    public String getSaveQuartzJobUrl() {
        return this.getApiUrl() + this.getPropertyValue("saveQuartzJobUrl");
    }

    /**
     * 运行quartz接口
     *
     * @return
     */
    public String getRunQuartzJobUrl() {
        return this.getApiUrl() + this.getPropertyValue("runQuartzJobUrl");
    }


    public String getDeleteQuartzJobUrl() {
        return this.getApiUrl() + this.getPropertyValue("deleteQuartzJobUrl");
    }

    /**
     * 更新quartz接口
     *
     * @return
     */
    public String getUpdateQuartzJobUrl() {
        return this.getApiUrl() + this.getPropertyValue("updateQuartzJobUrl");
    }
}
